package com.cwt_taxi_xa;

import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

import com.cwt_taxi_xa.constants.ConstantsState;
import com.cwt_taxi_xa.util.GPIOUtil;

public class ActivityACC extends CWTBaseActivity{

	public static boolean accon = true;

	Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			finish();
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.openSwipeBack(false);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_aa_acc);

		try {
			Settings.System.putInt(getContentResolver(),
					Settings.System.SCREEN_BRIGHTNESS, 0);
		} catch (Exception localException) {
			localException.printStackTrace();
		}



		TextView tv = (TextView) findViewById(R.id.tv);
		tv.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				return true;
			}
		});

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		//背光
		GPIOUtil.writeToDevice(0, "/proc/bl_en");
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					GPIOUtil.writeToDevice(0, "/proc/bl_en");
				} catch (Exception e) {
				}
			}
		}).start();
		//右侧灯板
		GPIOUtil.writeToDevice(0, "/proc/panel_backlight");
		//左侧灯板
		GPIOUtil.writeToDevice(0, "/proc/rfid_pow_switch");
		GPIOUtil.writeToDevice(0, "/proc/red_switch");
		GPIOUtil.writeToDevice(0, "/proc/green_switch");
		GPIOUtil.writeToDevice(0, "/proc/yellow_switch");
		GPIOUtil.writeToDevice(0, "/proc/blue_switch");

		accon = false;
		ConstantsState.setStateValue(8, "0");

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		//背光
		GPIOUtil.writeToDevice(1, "/proc/bl_en");
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					GPIOUtil.writeToDevice(1, "/proc/bl_en");
				} catch (Exception e) {
				}
			}
		}).start();
		//右侧灯板
		GPIOUtil.writeToDevice(1, "/proc/panel_backlight");
		//左侧灯板
		GPIOUtil.writeToDevice(1, "/proc/rfid_pow_switch");
		GPIOUtil.writeToDevice(1, "/proc/red_switch");
		GPIOUtil.writeToDevice(1, "/proc/green_switch");
		GPIOUtil.writeToDevice(1, "/proc/yellow_switch");
		GPIOUtil.writeToDevice(1, "/proc/blue_switch");
		accon = true;
		ConstantsState.setStateValue(8, "1");



		Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 255);
//		try {
//			String h = new SimpleDateFormat("HH").format(new Date());
//			if(Integer.parseInt(h)>6&&Integer.parseInt(h)<18){
//				Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 255);
//			}else{
//				Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, 55);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void setStatus(int index, boolean status) {
		// TODO Auto-generated method stub

	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub
		if(type==404){
			handler.sendEmptyMessage(1001);
		}
	}

}
